/*
 * LocalTask.h
 *
 *  Created on: 2010-11-21
 *      Author: leo
 */

#ifndef LOCALTASK_H_
#define LOCALTASK_H_

#include "AbstractTask.h"

#include <vector>
#include <iostream>
#include <string>
#include "boost/date_time/posix_time/posix_time.hpp"
#include "boost/thread/thread.hpp"
#include "boost/thread/mutex.hpp"

using namespace std;
using namespace boost;
using boost::posix_time::ptime;
using boost::posix_time::second_clock;
//using boost::gregorian::date;
using boost::gregorian::days;
//using namespace boost::posix_time;
using boost::thread;

typedef string			Person;
typedef std::vector < string >	Persons;
typedef	long long		TaskID;

namespace GTD {

class TaskIDGen {
	static TaskID	_base;
	static mutex	_mutex;
public:
	static bool	genID(TaskID& id);
	//TODO reload the base id when restart the timing engine
	static bool	reloadBaseID();
};

//class NotifyClock {
//public:
//	vector <>
//};

class LocalTask: public GTD::AbstractTask {
protected:
	string 	taskTitle;
	bool	expire;
	ptime 	startTime;
	ptime 	endTime;

	TaskID	id;
	Person	owner;
	string	location;
	Persons	personInvolved;
	//vector < string >	details;
public:
	LocalTask(string t);
	LocalTask(string t, ptime st, ptime et);
	void 	setLocation(string loc) {
		location = loc;
	}
	string	getLocation() {
		return location;
	}
	void	addPersonInvolved(Person p);
	time_duration stillLast();
	bool cancel();
//	bool restart();

	friend std::ostream& operator << (std::ostream& source, LocalTask& task) {
		source << "LocalTask <" << task.taskTitle << "> start from [" <<
				task.startTime << " TO " <<
				task.endTime << "]";
		return source;
	}

	virtual ~LocalTask();

	friend	bool	earlier(LocalTask& t1, LocalTask& t2);
};

}

#endif /* LOCALTASK_H_ */
